package  
{
	import Components.ChopperForm;
	import Components.Explosion;
	import flash.display.Graphics;
	import flash.geom.Vector3D;
	import flash.system.System;
	import nl.jorisdormans.phantom2D.audio.SfxrSound;
	import nl.jorisdormans.phantom2D.objects.boundaries.CollideWithLayerEdge;
	import nl.jorisdormans.phantom2D.objects.boundaries.WrapAround;
	import nl.jorisdormans.phantom2D.objects.GameObject;
	import nl.jorisdormans.phantom2D.objects.GameObjectComponent;
	import nl.jorisdormans.phantom2D.objects.IInputHandler;
	import nl.jorisdormans.phantom2D.objects.misc.Gravity;
	import nl.jorisdormans.phantom2D.objects.Mover;
	import nl.jorisdormans.phantom2D.objects.renderers.BoundingShapeRenderer;
	import nl.jorisdormans.phantom2D.objects.shapes.BoundingBoxAA;
	import nl.jorisdormans.phantom2D.objects.shapes.BoundingCircle;
	import nl.jorisdormans.phantom2D.core.InputState;
	import nl.jorisdormans.phantom2D.objects.shapes.BoundingPolygon;
	import nl.jorisdormans.phantom2D.objects.shapes.BoundingShape;
	import nl.jorisdormans.phantom2D.particles.ParticleEmiter;
	
	import Particles.ChopperParticle;
	import Controllers.KeyHandler;
	import Particles.ExplosionParticle;
	
	import Components.Sounds;
	import Components.Health;
	
	/**
	 * @author Sebastiaan
	 */
	
	public class Player extends GameObject 
	{
		public static var force : int = 300;				//Starting force of the player
		public static var gravity : int = 400;				//Starting gravity of the player
		public static var setF : Boolean = false;			//Boolean is being set if setForce function is called
		public static var setG : Boolean = false;			//Boolean is being set if setGravity function is called
		public static var positions : Vector3D				//The horizontal position of the player
		
		private var myGravity : Gravity;					//The gravity component
		private var holder : BoundingCircle;
		private var myRender : BoundingShapeRenderer;
		
		public function Player() 
		{
			holder = new BoundingCircle(20);
			addComponent(holder);
			myRender = new BoundingShapeRenderer(0xFF8000);
			addComponent(myRender);
			myRender.alpha = 0;
			myGravity = new Gravity(new Vector3D(force, gravity, 0));							//sets the gravity and force
			addComponent(myGravity);															//adds gravity to the player
			addComponent(new Mover(new Vector3D(), 1, 0, true));								//adds mover to the player
			addComponent(new KeyHandler(250));													//new keyhandler which uses only the left mouse button
			addComponent(new WrapAround());														//
			addComponent(new CollideWithLayerEdge(0.3, false, false));							//adds collider to the player object
			addComponent(new Health());															//adds health to the player	object
			addComponent(new ParticleEmiter(ChopperParticle, 100, 0, 1, 0, 0.4, 10, 0.5));		//adds smoke to the player object
		}
		
		// sets the gravity of the player
		public static function setGravity(g : int) : void
		{
			gravity = g;
			setG = true;
		}
		
		// sets the force of the player moving
		public static function setForce(f : int) : void
		{
			force = f;
			trace(force);
			setF = true;
		}
		
		//returns the gravity
		public static function getGravity() : int
		{
			return gravity;
		}
		
		//returns the force
		public static function getForce() : int
		{
			return force;
		}
		
		//Sets the force and gravity of the player if setF or setG is true
		override public function update(elapsedTime:Number):void 
		{
			super.update(elapsedTime);
			if (setF)
			{
				removeComponent(myGravity)
				myGravity = new Gravity(new Vector3D(force, gravity, 0));
				addComponent(myGravity);
				setF = false;
			}
			else if (setG)
			{
				removeComponent(myGravity)
				myGravity = new Gravity(new Vector3D(force, gravity, 0));
				addComponent(myGravity); 
				setG = false;
			}
			positions = ChopperGame.getPosition();
			
		}
		
		//handles message for the explosion particle
		override public function handleMessage(message:String, data:Object = null):int 
		{
			trace(message);
			switch(message)
			{
				case "Explosion":	ChopperGame.boom = true;
									break;
			}
			return super.handleMessage(message, data);
		}
	}
}